package com.jiepos.mpos.biz.appInfM.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.appInfM.service.OrganizationService;
import com.jiepos.mpos.common.entity.App_Ins_AppEntity;
import com.jiepos.mpos.common.entity.App_Ins_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;

/**
 *
 *
 * <p>标题: —— APP机构信息维护控制器</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @ProjectName:  [mpos]
 * @Package com.jiepos.mpos.biz.
 * @author 余翼膑
 * @version 1.0
 * @since 2017年9月22号
 * @history（历次修订内容、修订人、修订时间等）
 */

@Controller
@RequestMapping("organization")
public class OrganizationController extends BaseController {
    @Autowired
    private OrganizationService organizationService;

    /**
     * 进入机构app信息列表页面
     * @param request
     * @param response
     * @param pagination
     * @return
     */
    @RequestMapping("/getOrganizationList.do")
    public ModelAndView getOrganizationList(HttpServletRequest request, HttpServletResponse response, Pagination pagination){

        ModelAndView model = new ModelAndView("/module/appInfM/organization/insinf_organization_list");
        return super.getDetail(request, response, model);
    }
/**
 * 查询通道列表信息json数据
 * @param pagination
 * @param infEntity
 * @return
 */
@RequestMapping("/InsinfOrganizationListJson.do")
    public @ResponseBody
    Map getAppInsinfListJson(HttpServletRequest request,Pagination pagination, App_Ins_InfEntity infEntity){
        return organizationService.getOrganizationServiceList(request,pagination, infEntity);
    }
    /**
     * 进入机构信息详细页面
     * @param request
     * @param response
     * @param pagination
     * @param ins_app_uuid
     * @return
     */
    @RequestMapping("/getOrganizationDetail.do")
    public ModelAndView getOrganizationDetail(HttpServletRequest request, HttpServletResponse response,
                                        Pagination pagination,String ins_app_uuid) {
        ModelAndView model = new ModelAndView("/module/appInfM/organization/insinf_organization_detail");
        // 菜单编码
        Map infEntity = organizationService.getInsInfById(ins_app_uuid);
        model.addObject("infEntity", infEntity);
        return super.getDetail(request, response, model);
    }
    /**
     * 校验所属机构是否存在在APP表中
     * @param appInsAppEntity
     * @return
     */
    @RequestMapping("/exitInsApp.do")
    public @ResponseBody
    String exitInsApp(App_Ins_AppEntity appInsAppEntity,HttpServletResponse response,HttpServletRequest request) {
     String exitInsApp =  organizationService.exitInsApp(appInsAppEntity);
     System.out.println("是否存在{},"+exitInsApp);
        return exitInsApp;
    }
    /**
     * 保存机构
     * @param request
     * @param response
     * @param appInsAppEntity
     * @return
     */
    @RequestMapping("/saveOrganizationDetail.do")
    public ModelAndView saveOrganizationDetail(HttpServletRequest request, HttpServletResponse response, App_Ins_AppEntity appInsAppEntity) {

        organizationService.saveOrganization(appInsAppEntity, super.getLoginUser(request, response));
        Map map=super.getLoginUser(request, response);
        return new ModelAndView(new RedirectView("getOrganizationList.do"), map);
    }

    /**
     * 获取机构菜单树
     * @return
     */
    @RequestMapping("/getAppInfTree.do")
    @ResponseBody
    public List<Map<String, Object>> getAppInfTree(String searchText){
        return organizationService.getAppInfTree(searchText);
    }
}
